package com.sky.controller.admin;

import com.sky.constant.ShopConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;


/**
 * ClassName: ShopController
 * Package: com.sky.controller.admin
 * Description:
 *
 * @Author Dylan_Jun
 * @Create 2024/2/6 21:13
 * @Version 1.0
 */
@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "店铺操作接口")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    @ApiOperation("设置店铺状态")
    public Result setstatus(@PathVariable Integer status){
        log.info("设置店铺状态为：{}", status.equals( ShopConstant.ENABLE) ? "营业中" : "打烊中");
        redisTemplate.opsForValue().set(ShopConstant.SHOP_STATUS_KEY, status);
        return Result.success(status);
    }

    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getstatus(){
        log.info("获取店铺的状态");
        Integer shop_status = (Integer) redisTemplate.opsForValue().get(ShopConstant.SHOP_STATUS_KEY);
        return Result.success(shop_status);
    }

}
